package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.service.MarketConfigMallService;
import com.cskaoyan.market.service.impl.MarketConfigMallServiceImpl;
import com.cskaoyan.market.util.HttpUtil;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
@RestController
@RequestMapping("admin/config")
public class AdminConfigController{
    @Autowired
    MarketConfigMallService service;
    @GetMapping("mall")
    private Object mall(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        HashMap<String, String> data = service.getConfigMall();
        return ResponseUtil.ok(data);
    }
    @GetMapping("express")
    private Object express(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        HashMap<String, String> data = service.getConfigExpress();
        return ResponseUtil.ok(data);
    }
    @GetMapping("order")
    private Object order(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        HashMap<String, String> data = service.getConfigOrder();
        return ResponseUtil.ok(data);
    }
    @GetMapping("wx")
    private Object wx(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        HashMap<String, String> data = service.getConfigWx();
        return ResponseUtil.ok(data);
    }
    @PostMapping("mall")
    private Object mallP(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String requestBody = HttpUtil.getRequestBody(req);
        String mall_address = JacksonUtil.parseString(requestBody, "market_mall_address");
        String market_mall_latitude = JacksonUtil.parseString(requestBody, "market_mall_latitude");
        String market_mall_longitude = JacksonUtil.parseString(requestBody, "market_mall_longitude");
        String market_mall_name = JacksonUtil.parseString(requestBody, "market_mall_name");
        String market_mall_phone = JacksonUtil.parseString(requestBody, "market_mall_phone");
        String market_mall_qq = JacksonUtil.parseString(requestBody, "market_mall_qq");
        service.updataMall(mall_address,market_mall_latitude,market_mall_longitude,market_mall_name,market_mall_phone,market_mall_qq);
        return ResponseUtil.ok();
    }
    @PostMapping("express")
    private Object expressP(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String requestBody = HttpUtil.getRequestBody(req);
        String marketExpressFreightMin = JacksonUtil.parseString(requestBody, "market_express_freight_min");
        String marketExpressFreightValue = JacksonUtil.parseString(requestBody, "market_express_freight_value");
        service.updateExp(marketExpressFreightValue,marketExpressFreightMin);
        return ResponseUtil.ok();
    }
    @PostMapping("order")
    private Object orderP(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String requestBody = HttpUtil.getRequestBody(req);
        String marketOrderComment = JacksonUtil.parseString(requestBody, "market_order_comment");
        String marketOrderUnconfirm = JacksonUtil.parseString(requestBody, "market_order_unconfirm");
        String marketOrderUnpaid = JacksonUtil.parseString(requestBody, "market_order_unpaid");
        service.upOrder(marketOrderUnpaid,marketOrderUnconfirm,marketOrderComment);
        return ResponseUtil.ok();
    }
    @PostMapping("wx")
    private Object wxP(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String requestBody = HttpUtil.getRequestBody(req);
        String marketWxCatlogGoods = JacksonUtil.parseString(requestBody, "market_wx_catlog_goods");
        String marketWxCatlogList = JacksonUtil.parseString(requestBody, "market_wx_catlog_list");
        String marketWxIndexBrand = JacksonUtil.parseString(requestBody, "market_wx_index_brand");
        String marketWxIndexHot = JacksonUtil.parseString(requestBody, "market_wx_index_hot");
        String marketWxIndexNew = JacksonUtil.parseString(requestBody, "market_wx_index_new");
        String marketWxIndexTopic = JacksonUtil.parseString(requestBody, "market_wx_index_topic");
        String marketWxShare = JacksonUtil.parseString(requestBody, "market_wx_share");
        service.updateWx(marketWxShare,marketWxCatlogGoods,marketWxCatlogList,marketWxIndexBrand,marketWxIndexHot,marketWxIndexNew,marketWxIndexTopic);
        return ResponseUtil.ok();
    }
}
